﻿function pageLoad(sender, args) {
//    if (document.location.toString().indexOf("Login.aspx") == -1 && document.location.toString().indexOf("Error.aspx") == -1 &&
//         document.location.toString().indexOf("PageNotFound.aspx") == -1 && document.location.toString().indexOf("SoporteEnLinea.aspx") == -1) {
//        if (typeof (isHistoryBack) == "undefined" || isHistoryBack) {
//            window.location.reload();
//        }
//        else {
//            isHistoryBack = true;
//        }
//    }

    if (typeof (Util) != "undefined") {
        if (Util.IsChrome || Util.IsSafari || Util.IsFireFox || Util.IsOpera || Util.IsIE9) {
            Util.CreaElementUp($get('logo'));
            Util.SetScrollWindow();
        }
    }
    
    if (window.contentPageLoad) {
        window.contentPageLoad(sender, args);
    }

    if (typeof ($) != 'undefined')
        $(document).bind('keydown', HotKeys);
}

function HotKeys(event) {
    //ctrl + G
    if (event.ctrlKey && event.which == 71) {
        if (typeof (btnGuardar) != 'undefined') {
            $get(btnGuardar).click();
            return false;
        }
    }

    //ctrl + R
    if (event.ctrlKey && event.which == 82) {
        if (typeof (btnRegresar) != 'undefined') {
            $get(btnRegresar).click();
            return false;
        }
    }

    //ctrl + N
    if (event.ctrlKey && event.which == 78) {
        if (typeof (btnNuevo) != 'undefined') {
            $get(btnNuevo).click();
            return false;
        }
    }

    //ctrl + U
    if (event.ctrlKey && event.which == 85) {
        if (typeof (btnNuevo) != 'undefined') {
            $get(btnNuevo).click();
            return false;
        }
    }

    //ctrl + A
    if (event.ctrlKey && event.which == 65) {
        if (typeof (btnAgregar) != 'undefined') {
            $get(btnAgregar).click();
            return false;
        }
    }

    //ctrl + B
    if (event.ctrlKey && event.which == 66) {
        if (typeof (btnBuscar) != 'undefined') {
            $get(btnBuscar).click();
            return false;
        }
    }

    //ctrl + E
    if (event.ctrlKey && event.which == 69) {
        if (typeof (btnExportar) != 'undefined') {
            $get(btnExportar).click();
            return false;
        }

        if (typeof (btnExcel) != 'undefined') {
            $get(btnExcel).click();
            return false;
        }
    }

    //ctrl + I
    if (event.ctrlKey && event.which == 73) {
        if (typeof (btnImprimir) != 'undefined') {
            $get(btnImprimir).click();
            return false;
        }
    }

    //ctrl + O ->Ok
    if (event.ctrlKey && event.which == 79) {
        if (typeof (btnAceptar) != 'undefined') {
            $get(btnAceptar).click();
            return false;
        }
    }
}

//PopUp
function OpenPopUp(url, width, height, title) {
    if (typeof (url) == 'undefined' || url.length == 0) {
        return;
    }

    if (typeof (width) == 'undefined' || width.length == 0) {
        width = '100';
    }

    if (typeof (height) == 'undefined' || height.length == 0) {
        height = '100';
    }

    document.getElementById("dialog-form").innerHTML = "<iframe scrolling='no' id='iFramePopUp' frameborder='0' width='" + width.toString() + "', height='" + (parseInt(height) - 10).toString() + "', name='iFramePopUp' src='" + url + "'></iframe>";

    width = parseInt(width) + 50;
    height = parseInt(height) + 50;
    title = "CLab - " + title;

    $("#dialog-form").dialog({
        autoOpen: false,
        title:  title,
        width: width,
        height: height.toString(),
        modal: true,
        draggable: false,
        resizable: false,
        close: function () {
            document.getElementById("dialog-form").innerHTML = "";
            if (typeof (onClosed) != "undefined") {
                onClosed();
            }
        }
    });

    $("#dialog-form").dialog("open");

//    var options = {
//        'autoScale': false,
//        'autoDimensions': false,
//        'width': width,
//        'height': height,
//        'transitionIn': 'fade',
//        'transitionOut': 'fade',
//        'type': 'iframe',
//        'href': url,
//        'scrolling': scrolling,
//        'modal': modal,
//        'beforeClose': function () {
//            if (typeof (onClosed) != "undefined") {
//                onClosed();
//            }
//        }
//    }

//    $.fancybox(options);
}

function ClosePopUpCurrent()
{
    //$.fancybox.close();
    $("#dialog-form").dialog("close");
}

function ShowMsg(msg, fn, params) {
    $("#dialog")[0].innerHTML = "<p>" + msg.toString() + "</p>"
    $("#dialog").dialog({
        autoOpen: false,
        width: 400,
        draggable: false,
        buttons: [
				{
				    text: "Aceptar",
				    click: function () {
				        $(this).dialog("close");
				        if (typeof (fn) != "undefined") {
				            if (fn != null) {
				                if (typeof (params) == "undefined") {
				                    fn();
				                }
				                else {
				                    if (paramsOk != null) {
				                        switch (params.length) {
				                            case 0:
				                                fn();
				                                break;
				                            case 1:
				                                fn(params[0]);
				                                break;
				                            case 2:
				                                fn(params[0], params[1]);
				                                break;
				                            case 3:
				                                fn(params[0], params[1], params[2]);
				                                break;
				                            case 4:
				                                fn(params[0], params[1], params[2], params[3]);
				                                break;
				                            case 5:
				                                fn(params[0], params[1], params[2], params[3], params[4]);
				                                break;
				                            case 6:
				                                fn(params[0], params[1], params[2], params[3], params[4], params[5]);
				                                break;
				                            case 7:
				                                fn(params[0], params[1], params[2], params[3], params[4], params[5], params[6]);
				                                break;
				                            case 8:
				                                fn(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7]);
				                                break;
				                            case 9:
				                                fn(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8]);
				                                break;
				                            case 10:
				                                fn(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9]);
				                                break;
				                        }
				                    }
				                }
				            }
				        }
				    }
				}
			]
    });
    $("#dialog").dialog("open");
}

function ConfirmMsg(msg, fnOk, paramsOk, fnCancel, paramsCancel) {
    $("#dialog")[0].innerHTML = "<p>" + msg.toString() + "</p>"
    $("#dialog").dialog({
        autoOpen: false,
        width: 400,
        draggable: false,
        buttons: [
				{
				    text: "Aceptar",
				    click: function () {
				        $(this).dialog("close");
				        if (typeof (fnOk) != "undefined") {
				            if (fnOk != null) {
				                if (typeof (paramsOk) == "undefined") {
				                    fnOk();
				                }
				                else {
				                    if (paramsOk != null) {
				                        switch (paramsOk.length) {
				                            case 0:
				                                fnOk();
				                                break;
				                            case 1:
				                                fnOk(paramsOk[0]);
				                                break;
				                            case 2:
				                                fnOk(paramsOk[0], paramsOk[1]);
				                                break;
				                            case 3:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2]);
				                                break;
				                            case 4:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3]);
				                                break;
				                            case 5:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4]);
				                                break;
				                            case 6:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4], paramsOk[5]);
				                                break;
				                            case 7:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4], paramsOk[5], paramsOk[6]);
				                                break;
				                            case 8:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4], paramsOk[5], paramsOk[6], paramsOk[7]);
				                                break;
				                            case 9:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4], paramsOk[5], paramsOk[6], paramsOk[7], paramsOk[8]);
				                                break;
				                            case 10:
				                                fnOk(paramsOk[0], paramsOk[1], paramsOk[2], paramsOk[3], paramsOk[4], paramsOk[5], paramsOk[6], paramsOk[7], paramsOk[8], paramsOk[9]);
				                                break;
				                        }
				                    }
				                }
				            }
				        }
				    }
				},
		        {
		            text: "Cancelar",
		            click: function () {
		                $(this).dialog("close");
		                if (typeof (fnCancel) != "undefined") {
		                    if (fnCancel != null) {
		                        if (typeof (paramsCancel) == "undefined") {
		                            fnCancel();
		                        }
		                        else {
		                            if (paramsCancel != null) {
		                                switch (paramsCancel.length) {
		                                    case 0:
		                                        fnCancel();
		                                        break;
		                                    case 1:
		                                        fnCancel(paramsCancel[0]);
		                                        break;
		                                    case 2:
		                                        fnCancel(paramsCancel[0], paramsCancel[1]);
		                                        break;
		                                    case 3:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2]);
		                                        break;
		                                    case 4:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3]);
		                                        break;
		                                    case 5:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4]);
		                                        break;
		                                    case 6:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4], paramsCancel[5]);
		                                        break;
		                                    case 7:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4], paramsCancel[5], paramsCancel[6]);
		                                        break;
		                                    case 8:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4], paramsCancel[5], paramsCancel[6], paramsCancel[7]);
		                                        break;
		                                    case 9:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4], paramsCancel[5], paramsCancel[6], paramsCancel[7], paramsCancel[8]);
		                                        break;
		                                    case 10:
		                                        fnCancel(paramsCancel[0], paramsCancel[1], paramsCancel[2], paramsCancel[3], paramsCancel[4], paramsCancel[5], paramsCancel[6], paramsCancel[7], paramsCancel[8], paramsCancel[9]);
		                                        break;
		                                }
		                            }
		                        }
		                    }
		                }
		            }
		        }
			]
    });
    $("#dialog").dialog("open");
}